﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GBits.ContactUtilites;

namespace GBits.ContactManager
{
    public partial class frmSettings : Form
    {
        public frmSettings()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            UserOptions.dataDirectory = tbDataPath.Text;
            if (rbHLeft.Checked)
                UserOptions.helpDock = DockStyle.Left;
            else UserOptions.helpDock = DockStyle.Right;
            if (rbTbDisable.Checked)
                UserOptions.toolbarVisible = false;
            else UserOptions.toolbarVisible = true;
            if (rbTVLeft.Checked)
                UserOptions.treeDock = DockStyle.Left;
            else UserOptions.treeDock = DockStyle.Right;
            if (rbEventListLeft.Checked)
                UserOptions.eventDock = DockStyle.Left;
            else UserOptions.eventDock = DockStyle.Right;

            DataAccess.GetData().SaveOptions(UserOptions.GetOptions().toXml());

            frmHelp.GetForm().Dock = UserOptions.helpDock;

            DataAccess.GetData().SaveOptions(UserOptions.GetOptions().toXml());

            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog.SelectedPath = UserOptions.dataDirectory;
            if(FolderBrowserDialog.ShowDialog() == DialogResult.OK)
                tbDataPath.Text = FolderBrowserDialog.SelectedPath;
        }

        private void frmSettings_Load(object sender, EventArgs e)
        {
            if (UserOptions.toolbarVisible)
                rbTbEnable.Checked = true;
            else rbTbDisable.Checked = true;

            if (UserOptions.helpDock == DockStyle.Left)
                rbHLeft.Checked = true;
            else rbHRight.Checked = true;

            if (UserOptions.treeDock == DockStyle.Left)
                rbTVLeft.Checked = true;
            else rbTVRight.Checked = true;

            if (UserOptions.eventDock == DockStyle.Left)
                rbEventListLeft.Checked = true;
            else rbEventListRight.Checked = true;

            tbDataPath.Text = UserOptions.dataDirectory;
        }


    }
}
